package com.translate.web.service.impl;

import com.translate.web.dao.CommissionManagementDetailMapper;
import com.translate.web.param.contract.IUserIdParam;
import com.translate.web.param.contract.IWithdrawalAddParam;
import com.translate.entity.CommissionManagementDetail;
import com.translate.web.service.ICommissionManagementDetailService;
import com.basic.service.impl.BaseServiceImpl;
import com.param.contract.IPage;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CommissionManagementDetailServiceImpl extends BaseServiceImpl<CommissionManagementDetail>
		implements ICommissionManagementDetailService {
	public CommissionManagementDetailServiceImpl(CommissionManagementDetailMapper mapper) {
		super(mapper);
	}

	protected void insertPropteris(CommissionManagementDetail data) {
		long time = System.currentTimeMillis() / 1000;
		data.setCreateTime(time);
		data.setUpdateTime(time);
	}

	protected void updatePropteris(CommissionManagementDetail data) {
		data.setUpdateTime(System.currentTimeMillis() / 1000);
	}

	protected Class<CommissionManagementDetail> getEntityClass() {
		return CommissionManagementDetail.class;
	}

	@Override
	protected CommissionManagementDetail getEntityInstance() {
		return new CommissionManagementDetail();
	}

	@Override
	protected <S extends IPage> String sqlByGetCounttAfterProcesser(S param) {
		
		IUserIdParam sqlParam = (IUserIdParam) param;
		
		Integer id = sqlParam.getUserId();
		
		return super.sqlByGetCount(" user_id = " + id);
	}

	@Override
	protected <S extends IPage> String sqlByGetPageListAfterProcesser(S param) {
		IUserIdParam sqlParam = (IUserIdParam) param;
		
		Integer id = sqlParam.getUserId();
		
		return super.sqlByGetPageList(" and  user_id = " + id);
	}
	
	protected boolean continueColumns(String columns) {
		return columns.equals("updateTime") || columns.equals("userId") || columns.equals("");
	}

	@Override
	@Transactional(propagation = Propagation.MANDATORY)
	public int addCommission(int commissionId, IWithdrawalAddParam addParam, byte type, String description) {
		
		CommissionManagementDetail data = new CommissionManagementDetail();
		
		data.setCommissionId(commissionId);
		
		data.setUserId((int) addParam.getUserId());
		
		data.setType(type);
		
		data.setMonry(addParam.getAmount());
		
		data.setDescription(description);
		
		return this.insert(data);
	}
}